﻿using BCL.BaseLib;
using BCL.BaseLib.Basics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using BCL.Tool;
namespace BCL.WPFComponent
{
    /// <summary>
    /// MainTopControl.xaml 的交互逻辑
    /// </summary>
    public partial class MainTopControl : UserControl
    {
      
        public MainTopControl()
        {
            InitializeComponent();
            this.click_maximize.MouseDown += maximize_Click;
            this.click_close.MouseDown += win_close;
            this.click_notify.MouseDown += win_click_notify;
        }

      

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            Window window=  Window.GetWindow(this);
            if (window != null && !string.IsNullOrEmpty(window.Title))
                textTitle.Text = window.Title.Language();
            //if (BCLApplication.AppFunMunes == null)
            //    return;
            //foreach (var item in BCLApplication.AppFunMunes)
            //{
            //    if (item.ItemType == FunctionItemType.Item && item.FunctionType == FunctionType.Control && item.IsCreate)
            //    {
            //        Border bd = new Border { Width = 20, Height = 20, Margin = new Thickness(0, 0, 10, 0),Tag=item };
            //        bd.Style = (Style)FindResource("BorderStyle");
                   
            //        bd.Child = new Image { Stretch = Stretch.Fill, Width = 20, Height = 20, Source = item.Image.ToBitmap() };

            //        bd.MouseDown += Bd_MouseDown;
            //        PanelBarItem.Children.Add(bd);
            //    }
            //}
        }

        private void Bd_MouseDown(object sender, MouseButtonEventArgs e)
        {
            BCLApplication.MainForm.OpenFunction(((Border)sender).Tag as FunctionEntity);
        }

        private void Border_MouseDown(object sender, MouseButtonEventArgs e)
        {
            BCLApplication.MainForm.OpenMenu();
        }

        private void win_click_notify(object sender, MouseButtonEventArgs e)
        {
            Window.GetWindow(this).WindowState = WindowState.Minimized;
        }
        private void maximize_Click(object sender, RoutedEventArgs e)
        {
            Window win = Window.GetWindow(this);
            win.WindowState = win.WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
          
        }

        private void win_close(object sender, RoutedEventArgs e)
        {
            Window.GetWindow(this).Close();
        }

    }
}
